from rest_framework.response import Response
from rest_framework.pagination import PageNumberPagination
# 重写PageNumberPagination里面的返回分页函数
class MyPage(PageNumberPagination):
    page_size = 5  # 默认按照10个每页划分
    max_page_size = 100  # 每页的最大数据
    page_query_param = 'next'# 前端传过来的页数
    page_size_query_param = 'previous'# 前端传过来的每页数据
    def get_paginated_response(self,data):
        """
        功能：构建响应对象(封装响应参数)
        :param data: 当前页数据
        :return:
        """
        # dict = []
        # for i in data:
        #     # for x in i:
        #     #     pass
        #      dict.append(i)


        return Response({
            'count':self.page.paginator.count,
            'results':data,
            'next':self.page.number,
            # 'pages':self.page.paginator.num_pages,
            'previous':self.page_size # 后端默认每页数据
        })